package com.example.tests;

import static com.example.tests.ContactDataGenerator.loadContactsFromXmlFile;
import static com.example.tests.ContactDataGenerator.loadContactsFromCsvFile;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.io.File;
import java.util.Iterator;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.example.fw.datamapping.ContactLine;
import com.example.utils.SortedListOf;

public class ContactCreationTests  extends TestBase {

	@DataProvider	
	public Iterator<Object[]> contactsFromFile() throws Exception{
		return wrapContactsForDataProvider(loadContactsFromCsvFile(new File("contacts.txt"))).iterator();
	}
	
	@Test (dataProvider = "contactsFromFile")
	public void testNonEmptyContactCreation(ContactData contact) throws Exception {
		SortedListOf<ContactLine> oldContactLineList = app.getContactHelper().getContactLines();

		app.getContactHelper().contactCreation(contact);
		
		SortedListOf<ContactLine> newContactLinesList = app.getContactHelper().getContactLines();

		assertThat(newContactLinesList, equalTo(oldContactLineList.withAdded(contact.toContactLine())));
	}
}
